package www.ycobi.com;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class DBHandler {
	private DBHelper helper;
	private SQLiteDatabase db;
	
	public DBHandler(Context ctx) {
		this.helper = new DBHelper(ctx);
		this.db = helper.getWritableDatabase();
	}
	
	public static DBHandler open(Context ctx) throws SQLException{
		DBHandler handler = new DBHandler(ctx);
		return handler;
	} 
	
	public void close(){
		helper.close();
	}
	
	public long insert(String car_name){
		ContentValues values = new ContentValues();
		values.put("car_name", car_name);
		return db.insert("cars", null,values);
	}
	
	public Cursor select(int id) throws SQLException{
		Cursor cursor = db.query(true, "cars", new String[]{"_id","car_name"}, "_id"+"="+id, null, null, null, null, null);
		if(cursor != null){cursor.moveToFirst();}
		return cursor;
	}
	
}
